// pages/my/set/myAddress/myAddress.js
var app = getApp()
Page({
  data: {
    agentId:'',
    addressList:[]
  },
  onLoad: function (options) {
    let type = options.type   //1 卖货跳转
    if (type==1){
      wx.setNavigationBarTitle({
        title: '管理地址' 
      })
    }else{
      wx.setNavigationBarTitle({
        title: '我的收货地址' 
      })
    }
    app.getMemInfo().then(res=>{
      this.setData({
        agentId:res.data.agentId
      })
      this.getAddressList(res.data.agentId)
    })

  },
  onShow(){
    app.getMemInfo().then(res=>{
      this.setData({
        agentId:res.data.agentId
      })
      this.getAddressList(res.data.agentId)
    })
  },
  getAddressList(agentId){
    let data = {
      agentId
    }
    app.request('wx_app/agent/address/list',data,'GET').then(res=>{
      console.log(res)
      this.setData({
        addressList:res.data
      })
    })
  },
  editAddress(e){
    let data = e.currentTarget.dataset
    let address = JSON.stringify(data.address)
    if (data.type==0){ //0编辑1添加
      wx.navigateTo({
        url:'../../myFactory/editMyFactory?type=0&address='+address
      })
    }else{
      wx.navigateTo({
        url:'../../myFactory/editMyFactory?type=1'
      })
    }
    
  }
})
